<style>
    *{
        font-size: 14px;
        margin: 0;
        padding: 0;
    }
    a {
        text-decoration: none;
    }
    .content{
        width: 1024px;
        margin: 20px auto;
    }
    .logo {
        font-size: 30px;
        font-weight: bold;
    }
    .add-btn {
        margin-top: 20px;
    }
    .add-btn a {
        background-color: #cc0000;
        font-weight: bold;
        color: #ffffff;
        padding: 5px 10px;
        border-radius: 5px;
    }
    .book-lists{
        width: 100%;
        border-collapse: collapse;
        margin-top: 20px;
    }
    .book-lists tr td, .book-lists tr th {
        border: 1px solid #000000;
        padding: 5px;
    }
</style>

<div class="content">
    <div class="top">
        <div class="logo">图书管理系统v1.0</div>
    </div>
    <div class="add-btn">
        <a href="/index.php?c=book&a=add">添加图书</a>
    </div>

    <table class="book-lists">
        <thead>
        <tr>
            <th>序号</th><th>书名</th><th>ISBN</th><th>出版社</th><th>库存</th><th>创建时间</th><th>操作</th>
        </tr>
        </thead>
        <tbody>
        <?php foreach ($items as $key => $val):?>
            <tr>
                <td><?php echo $key + 1;?></td>
                <td><?php echo $val['title'];?></td>
                <td><?php echo $val['isbn'];?></td>
                <td><?php echo $val['publish'];?></td>
                <td><?php echo $val['stock'];?></td>
                <td><?php echo $val['created_at'];?></td>
                <td align="center">
                    <a href="/index.php?c=book&a=edit&book_id=<?php echo $val['id'];?>">编辑</a> |
                    <a href="javascript:deleteBook(<?php echo $val['id'];?>, '<?php echo $val['title']?>')">删除</a> |
                    <a href="/index.php?c=record&a=add&book_id=<?php echo $val['id'];?>">借阅</a> 
                </td>
            </tr>
        <?php endforeach;?>
        </tbody>
    </table>
</div>

<script>
    function deleteBook(book_id, title) {
        if (confirm('是否确认删除《' + title + '》图书')) {
            window.location.href="/index.php?c=book&a=delete&book_id=" + book_id
        }
    }
</script>



